package com.example.mvvmdemo.http.mtv;

import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;

import com.blankj.utilcode.util.LogUtils;
import com.example.mvvmdemo.AppConstants;
import com.example.mvvmdemo.http.BaseObserver;
import com.example.mvvmdemo.model.Mtv;
import com.example.mvvmdemo.model.PageInfo;
import com.example.mvvmdemo.model.mtvdetail.Movie;

public class MtvViewModel extends ViewModel {

    private final MutableLiveData<PageInfo<Mtv>> mtvList = new MutableLiveData<>();
    private final MutableLiveData<Movie> mv = new MutableLiveData<>();

    public MutableLiveData<PageInfo<Mtv>> getMtvList() {
        return mtvList;
    }

    public MutableLiveData<Movie> getMv() {
        return mv;
    }

    public void getMtvList(int page_start){
        RetrofitHelper.getInstance()
                .getMvtvList("movie", "热门", 10, page_start * 10)
                .subscribe(new BaseObserver<PageInfo<Mtv>>() {
                    @Override
                    public void onNext(PageInfo<Mtv> response) {
                        super.onNext(response);
                        mtvList.setValue(response);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                });
    }

    public void getMvtvData(String id) {
        RetrofitHelper.getInstance(AppConstants.API_BASEURL)
                .getMvtvData(id)
                .subscribe(new BaseObserver<Movie>() {
                    @Override
                    public void onNext(Movie movie) {
                        super.onNext(movie);
                        mv.setValue(movie);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                });
    }
}
